package com.chen.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.chen.pojo.Task;
import com.chen.pojo.User;
import com.chen.service.TaskService;
import com.chen.service.UserService;

@Controller
public class TaskController {
	@Autowired
	private TaskService taskService;
    @RequestMapping (value="quartz")
   
    public String  login(){
    	System.out.println(123);
    	///SSM/pages/home/home.html.html
    	//照着这个改路径 就行了 你现在的路径是在/ssm/下 所以要先..,c
    	return "../pages/home/quartz";  
        
    }
    
    @ResponseBody
    @RequestMapping (value="getTaskList")
    public Map test(){
        List list=taskService.getTask();
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("total", 1);
        map.put("rows", list);
//        list.add("中文");
//        list.add("2");
//        list.add("3");
//        User user=taskService.getUserById("1");
        System.out.println("tasklist");
        return map;
        
    }
    
    @ResponseBody
    @RequestMapping (value="addTask")
    public Map  addTask(@RequestParam(required = false) String taskName,
    		@RequestParam(required = false) String groupName,
    		@RequestParam(required = false) String className){
		
    	Task task =new Task();
    	task.setClassName(className);
    	task.setGroupName(groupName);
    	task.setTaskName(taskName);
    	task.setDescName("描述");
    	taskService.addTask(task);
    	Map<String,Object> map=new HashMap<String,Object>();
    	return map;
    	///SSM/pages/home/home.html.html
    	//照着这个改路径 就行了 你现在的路径是在/ssm/下 所以要先..,c
    	//return "../pages/home/home";  
        
    }
    
    @ResponseBody
    @RequestMapping (value="deleteTask")
    public Map  deleteTask(@RequestParam(required = false) String taskName){

    	taskService.deleteTask(taskName);
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("success", "true");
    	return map;
    	///SSM/pages/home/home.html.html
    	//照着这个改路径 就行了 你现在的路径是在/ssm/下 所以要先..,c
    	//return "../pages/home/home";  
        
    }
    
    @ResponseBody
    @RequestMapping (value="updateTask")
    public Map  updateTask(@RequestParam(required = false) String taskName){

    	Task task =taskService.getTaskByName(taskName);
    	task.setDescName("描述123");
    	taskService.updateTask(task);
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("success", "true");
    	return map;
    	///SSM/pages/home/home.html.html
    	//照着这个改路径 就行了 你现在的路径是在/ssm/下 所以要先..,c
    	//return "../pages/home/home";  
        
    }
}
